﻿#include <iostream>
#include "include/API.h"
#include <Windows.h>

int main() {
    SetConsoleOutputCP(65001);
    SetConsoleCP(65001);
    std::string key;
    std::cout << "书名/bookid:";
    std::cin >> key;
    //搜索
    int flag;
    int offset = 0;
    std::vector<Novel> novels;
    while (TRUE) {
        novels = search_novel(key, offset);
        if (novels.empty()) {
            std::cout << "没有更多结果了！" << std::endl;
            break;
        }
        display_novels(novels);
        std::cout << "输入数字选择书本, 输入-1进入下一页, 输入0退出: ";
        std::cin >> flag;
        if (flag == -1) {
            offset += 10; // 进入下一页
            std::cout << "加载下一页..." << std::endl; /**/
        } else if (flag == 0) {
            std::cout << "程序退出" << std::endl;
            return 0;
        } else if (flag > 0 && flag <= static_cast<int>(novels.size())) {
            // 选择书本，退出循环进行下载
            std::cout << "选择了第 " << flag << " 本书" << std::endl;
            break;
        } else {
            std::cout << "输入无效，请重新输入！" << std::endl;
        }
    }
    std::vector<Chapter> chapters = get_novel_chapter(novels[flag - 1].book_id);
    std::cout << "确认下载?";
    system("pause");
    return 0;
}
